﻿using System.Runtime.Serialization;
using ESRI.ArcGIS.Geometry;

namespace PlanningGIS.ArcGIS.Custom
{
    /// <summary>
    /// 概述：矩形<br />
    /// </summary>
    [DataContract]
    public class Envelope
    {
        /// <summary>
        /// 获取或设置空间参考。
        /// </summary>
        [DataMember(Name = "spatialReference")]
        public SpatialReference SpatialReference { get; set; }

        /// <summary>
        /// 获取或设置 XMax。
        /// </summary>
        [DataMember(Name = "xmax")]
        public double XMax { get; set; }

        /// <summary>
        /// 获取或设置 XMin。
        /// </summary>
        [DataMember(Name = "xmin")]
        public double XMin { get; set; }

        /// <summary>
        /// 获取或设置 YMax。
        /// </summary>
        [DataMember(Name = "ymax")]
        public double YMax { get; set; }

        /// <summary>
        /// 获取或设置 YMin。
        /// </summary>
        [DataMember(Name = "ymin")]
        public double YMin { get; set; }

        /// <summary>
        /// 格式转换。
        /// </summary>
        /// <param name="envelope"></param>
        /// <returns></returns>
        public static Envelope Parse(IEnvelope envelope)
        {
            if (envelope == null)
            {
                return null;
            }

            return new Envelope()
            {
                XMax = envelope.XMax,
                XMin = envelope.XMin,
                YMax = envelope.YMax,
                YMin = envelope.YMin,
                SpatialReference = new SpatialReference()
                {
                    WKID = envelope.SpatialReference.FactoryCode
                }
            };
        }
    }
}
